package com.bphx.android.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.bphx.android.R;
import com.bphx.android.activities.dialogs.ErrorDialog;

import static com.bphx.android.R.id.et_password;
import static com.bphx.android.R.id.et_user_name;
import static com.bphx.android.R.layout.network_manager;
import static com.bphx.android.R.string.errorEmptyCredentials;
import static com.bphx.android.utils.Constants.PASSWORD;
import static com.bphx.android.utils.Constants.USER_NAME;
import static com.bphx.android.utils.Utils.getTextFrom;
import static org.apache.commons.lang.StringUtils.isBlank;

/**
 * @author Vyacheslav Kovalyov
 * @version 1.0
 */
public class NetworkManagerActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(network_manager);

        unTextView = (TextView) findViewById(et_user_name);
        pwdTextView = (TextView) findViewById(et_password);

        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        findViewById(R.id.btnMerge).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String un = getTextFrom(unTextView);
                String pwd = getTextFrom(pwdTextView);

                if (isBlank(un) || isBlank(pwd)) {
                    new ErrorDialog(NetworkManagerActivity.this, errorEmptyCredentials).show();
                    return;
                }

                Intent intent = new Intent(NetworkManagerActivity.this, DownloadStatusActivity.class);
                intent.putExtra(USER_NAME, un);
                intent.putExtra(PASSWORD, pwd);

                startActivity(intent);
            }
        });
    }

    private TextView unTextView;
    private TextView pwdTextView;
}